<?php
/**
 * @fileoverview	
 * @author          zhanglei11
 * @date			Feb  02 11:31:49 CST 2012
 * @copyright       sina meila
 */
include_once ('../../__global.php');



class feed extends ml_controller{
	
	private $page = 1;
	private $pagesize = 10;
	
	private $_feedlist;
	private $_contentlist;
	private $_nicks;
	
public function initParam()
	{
		$this->page = abs((int)$this->input('page' , 'g' , 1));
	}

	public function checkParam()
	{
		//检查权限
		if(!$this->check_permission(ML_PERMISSION_LOGIN_ONLY)) {
			$this->redirect(ML_PAGE_LOGIN);
		}
		else if(!$this->check_permission(ML_PERMISSION_LOGIN_CANWRITE)) {
			$this->redirect(ML_PAGE_ACTIVE);
		}
		
		
	}
	public function main()
	{
		$uid = $this->__visitor['uid'];
		
		
		
		//获得我关注的人的uid
		$oFollow = new ml_model_dbFollow();
		
		$oFollow->getList($uid,0,200);
		$rs = $oFollow->get_data();
		
		foreach($rs as $k => $v) {
			$uidlist[] = $v['follow_uid'];
		}
		
		$uidlist[] = $uid;
		
		$data = array();
		//获取用户名片信息		
		$obizUser = ml_biz_user_getinfo::get_instance();
		$obizUser->initUser($uid,$uid);
		
		$arr = $obizUser->getUserArea();
		$data = array_merge($data,$arr);	// $data 从头到尾没有用啊？
		
		$oFeed = new ml_model_dbPublicFeed();
		$rs = $oFeed->getListByUids($uidlist);
		
		if(!$rs)		
			$this->redirect(ML_PAGE_SYSTEM_BUSY);
			
		$feed = $oFeed->get_data();
		
		
		$htmlModel=new ml_biz_user_feed();
		
		$auid[] = $uid;		//	这些UID是？
		$Acontent = $htmlModel->get_html($feed, $auid,true);
		$finnal['content']=$Acontent;
		
		//	找出当前用户信息
		$obizUser = ml_biz_user_getinfo::get_instance();
		$obizUser->initUser($uid,$uid);
		$arr = $obizUser->getUserArea();
		$data = array_merge($data,$arr);
		
		$finnal = array_merge($finnal,$data);
 			/**
			 * @todo 取数字
			 */
			
			
		/* 	
			$this->_nicks = ml_tool_nick::uids2nicks($aActUid);
			$oBizAtNick = new ml_biz_user_atNick();
			 */
		//	获得总数
		
		$rs = $oFeed->getCntByUids($uidlist);
		$cnt = $oFeed->get_data();
		$this->total = isset($cnt[0]) ? $cnt[0] : 0;
		
		
		
		$last=$this->total['num']-($this->page-1)* ML_FEED_PAGESIZE * 3 <ML_FEED_PAGESIZE?true:false;
		$this->set_scope_var('$totalPage', floor($this->total['num']/(ML_FEED_PAGESIZE * 3)+1));//总页数
		$this->set_scope_var('$currentPage', intval($this->page));//当前页
		$this->set_scope_var('$segment', 1);
		$this->set_scope_var('$lastSegment', $last);
		
		$this->page_output('feed' , $finnal);
		
	}
	
	


}
new feed();
?>